package com.ailink.concurrent.thread;

/**
 * Created by Administrator on 2018/10/9
 */
public class ThreadState extends Thread {

    private static Object lock = new Object();

    @Override
    public void run() {
        synchronized (lock) {
            while (true) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        Thread t1 = new ThreadState();
        t1.start();
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Thread t2 = new ThreadState();
        t2.start();

        while (true) {
            System.out.println(t1.getState());
            System.out.println(t2.getState());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
